ValidationResult

A result of any type T that is wrapped with an optional error message

Used to provide contextual error information "upstream" of where the error was encountered, which allows for better logging where upstream elements can collate error messages passed back to them into an organized and sensible error log.

This class has a private constructor to force the use of the pre-defined static instantiation methods

Author

fzzyhmstrs

Since

0.1.0

Parameters

T

result type, can be nullable

Types

Link copied to clipboard
object Companion
Link copied to clipboard
sealed interface ErrorEntry

Error context stored in a ValidationResult. This can represent an errored or non-errored state, can include multiple children contexts, and can include non-textual information (see ValidationResult.Errors.ACTION for example)

Link copied to clipboard
object Errors

Functions

Link copied to clipboard

Adds another test, and potentially another error, to a Validation.

Link copied to clipboard

Reports errors in this validation to an error consumer.

Link copied to clipboard

Maps this validation to a new type using a mapping function

Link copied to clipboard

Inspects the error of the result, if any, for errors of a particular type

Link copied to clipboard
fun get(): T

Gets the wrapped result value

Link copied to clipboard

Supplies the error message stored within

Link copied to clipboard

Supplies the error context stored within, if any

Link copied to clipboard

Tests whether this results error entry contains the specified error type.

Link copied to clipboard

Maps this validation to a new type using a mapping function

Link copied to clipboard

Boolean check to determine if this result is holding a critical (exception-caused) error

Link copied to clipboard

Boolean check to determine if this result is holding an error

Link copied to clipboard

Boolean check to determine if this result is valid (no errors)

Link copied to clipboard

Iterates over all ErrorEntry.Entry contained in this result

Provides an iterable containing any applicable ErrorEntry.Entry of the provided type

Link copied to clipboard
fun log(writer: BiConsumer<String, Throwable?> = ErrorEntry.ENTRY_WARN_LOGGER): ValidationResult<T>

Log this result if it is errored.

Link copied to clipboard
fun logPlain(writer: BiConsumer<String, Throwable?> = ErrorEntry.ENTRY_WARN_LOGGER): ValidationResult<T>

Log this result if it is errored.

Link copied to clipboard

Maps this validation's stored value to a new type using a mapping function

Link copied to clipboard

Maps this validation's stored value to a new type using a mapping function

Link copied to clipboard

reports error, if any, to a provided reporter (such as a logger)

reports error, if any, to a provided string list

Link copied to clipboard

Reports errors in this validation to an error consumer.

Link copied to clipboard

Performs the provided predicate test on this results error entry and any of its children. Generally returns true on the first success.

Performs the provided predicate test on this results error entry and any of its children if they are of the provided type. Generally returns true on the first success.

Link copied to clipboard
open override fun toString(): String
Link copied to clipboard

Creates a new ValidationResult of type T wrapping the new value with the error(if any) from the receiver ValidationResult (of any type, does not need to match T)

Link copied to clipboard
fun writeError(errors: List<String>)

Writes an error log to console if this validation result is errored

Link copied to clipboard
fun writeWarning(errors: List<String>)

Writes a warning log to console if this validation result is errored